﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Contacto
{
    public partial class eliminar : Form
    {
        public eliminar()
        {
            InitializeComponent();
        }

        private void btn_buscar_Click(object sender, EventArgs e)
        {
            btn_eliminar.Enabled = false;
            if (tx_name.Text != " " && tx_name.Text != "")
            {
                string nombre = tx_name.Text;
                string r_name = @"Contactos\\" + nombre + "\\name";
                if (System.IO.File.Exists(r_name))
                {
                    string w_name;
                    System.IO.StreamReader temp0 = new System.IO.StreamReader(r_name);
                    w_name = temp0.ReadToEnd();
                    temp0.Close();
                    tx_Dispo.Text = "Si disponible";
                    btn_eliminar.Enabled = true;
                    btn_buscar.Enabled = false;
                }
                else
                {
                    MessageBox.Show("No existe ese contacto", "Aviso de error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    tx_name.Text = "";
                }
            }
        }

        private void btn_eliminar_Click(object sender, EventArgs e)
        {
            string nombre = tx_name.Text;
            string ruta = @"Contactos\\" + nombre;
            System.IO.File.Delete(ruta + "\\lastname");
            System.IO.File.Delete(ruta + "\\day");
            System.IO.File.Delete(ruta + "\\mes");
            System.IO.File.Delete(ruta + "\\year");
            System.IO.File.Delete(ruta + "\\phone");
            System.IO.File.Delete(ruta + "\\mail");
            System.IO.File.Delete(ruta + "\\address");
            System.IO.File.Delete(ruta + "\\name");
            System.IO.Directory.Delete(ruta);
            btn_buscar.Enabled = true;
            tx_name.Text = "";
            tx_Dispo.Text = "No disponible";
            btn_eliminar.Enabled = false;
        }

        private void brn_Cancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


